//
//  DetailFourthVC.m
//  HomeFurnishing
//
//  Created by dllo on 16/4/8.
//  Copyright © 2016年 YMing. All rights reserved.
//

#import "DetailFourthVC.h"

@interface DetailFourthVC ()<UIScrollViewDelegate>
@property(nonatomic, retain)UIScrollView *scrView;
@property(nonatomic, retain)UIImageView *imgView;
@property(nonatomic, retain)UILabel *label;
@end
@implementation DetailFourthVC
-(void)dealloc
{
    [_scrView release];
    [_imgView release];
    [_idArr release];
    [_heightArr release];
    [_widthArr release];
    [_label release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBarHidden = YES;
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self createScrollView];
    self.label = [[UILabel alloc] init];
    _label.textColor = [UIColor whiteColor];
    _label.textAlignment = 1;
    _label.text = [NSString stringWithFormat:@"1/%ld",self.widthArr.count];
    _label.frame = CGRectMake(0, SCREEN_HEIGHT - 40, SCREEN_WIDTH, 30);
    [self.view addSubview:_label];
    [_label release];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(back:)];
    tap.numberOfTapsRequired = 1;
    [self.view addGestureRecognizer:tap];
    
    
}

-(void)back:(UITapGestureRecognizer *)tap
{
    self.navigationController.navigationBarHidden = NO;
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)createScrollView
{
    self.scrView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _scrView.contentSize = CGSizeMake(SCREEN_WIDTH *self.widthArr.count, SCREEN_HEIGHT);
    _scrView.alwaysBounceHorizontal = YES;
    _scrView.delegate =self;
    _scrView.backgroundColor = [UIColor blackColor];
    _scrView.pagingEnabled = YES;
    [self.view addSubview:_scrView];
    [_scrView release];
    [self addImageView];
}
-(void)addImageView
{
    
    for (NSInteger i = 0; i<self.widthArr.count; i++) {
        NSString *str = [NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w%@_h%@_m0.jpg",self.widthArr[i][@"id"],self.widthArr[i][@"width"],self.widthArr[i][@"height"]];
        self.imgView = [[UIImageView alloc] init];
        self.imgView.frame = CGRectMake(SCREEN_WIDTH *i, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        self.imgView.contentMode = UIViewContentModeScaleAspectFit;
        self.imgView.clipsToBounds = YES;
        self.imgView.userInteractionEnabled = YES;
        [self.imgView sd_setImageWithURL:[NSURL URLWithString:str]];
        [_scrView addSubview:_imgView];
        [_imgView release];
    }

}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.x>0&&scrollView.contentOffset.x<self.widthArr.count*SCREEN_WIDTH) {
        
        CGFloat i = (scrollView.contentOffset.x+SCREEN_WIDTH)/SCREEN_WIDTH;
        NSInteger j = i;
        _label.text = [NSString stringWithFormat:@"%ld/%ld",j,self.widthArr.count];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
